unit MAIN;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, Menus,
  StdCtrls, Dialogs, Buttons, Messages, ExtCtrls, ComCtrls, StdActns,
  ActnList, ToolWin, ImgList, DB, ADODB, cxClasses, dxBar, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinFoggy, dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSharp, dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinXmas2008Blue,
  dxSkinsdxBarPainter, cxLookAndFeels, dxSkinsForm, cxLookAndFeelPainters;

type
  TMainForm = class(TForm)
    StatusBar: TStatusBar;
    ImageList1: TImageList;
    ADOConnection1: TADOConnection;
    dxBarManager1: TdxBarManager;
    MainMenu: TdxBar;
    dxmFile: TdxBarSubItem;
    dxmExit: TdxBarButton;
    dxmHelp: TdxBarSubItem;
    dxmAbout: TdxBarButton;
    tTablesFields: TADOQuery;
    tTablesFieldsID: TAutoIncField;
    tTablesFieldsTableId: TIntegerField;
    tTablesFieldsFieldName: TWideStringField;
    tTablesFieldsFieldCaption: TWideStringField;
    tTablesFieldsNN: TIntegerField;
    tTablesFieldsWidth: TIntegerField;
    tTables: TADOQuery;
    tTablesID: TAutoIncField;
    tTablesTableName: TWideStringField;
    tTablesTableDescription: TWideStringField;
    tTablesNN: TIntegerField;
    tTablesFieldsLookUp: TWideStringField;
    tTablesMenu: TWideStringField;
    dxSkinController1: TdxSkinController;
    dxmSkins: TdxBarListItem;
    dxmSkinsMnu: TdxBarSubItem;
    dxmNoSkin: TdxBarButton;
    procedure dxmExitClick(Sender: TObject);
    procedure dxmAboutClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure dxmSkinsClick(Sender: TObject);
    procedure dxmNoSkinClick(Sender: TObject);
  private
    { Private declarations }
    mnus: TStringList;
    procedure CreateVocChild(const ID: Integer);
  public
    { Public declarations }
    procedure VocabularyClick(Sender: TObject);
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

uses CHILDWIN, about;


procedure TMainForm.FormCreate(Sender: TObject);
var
  btn: TdxBarButton;
  mnu: TdxBarSubItem;
  s: String;
  i: Integer;
  APainters: TcxExtendedStylePainters;
begin
  ADOConnection1.Close;
  ADOConnection1.ConnectionString :=
    'Provider=Microsoft.ACE.OLEDB.12.0;Data Source='+ExtractFilePath(ParamStr(0))+'Data\SpecPostavka.accdb';

  APainters := GetExtendedStylePainters;
  for i := 0 to APainters.Count - 1 do dxmSkins.Items.Add(APainters.Names[i]);

  mnus := TStringList.Create;

  ADOConnection1.Open;
  tTables.Open;
  tTablesFields.Open;

  while not tTables.Eof do begin
    s := tTablesMenu.AsString;
    i := mnus.IndexOf(s);
    if i < 0 then begin
      mnu := TdxBarSubItem.Create(Self);
      mnu.Caption := s;
      i := mnus.AddObject(s, mnu);
      MainMenu.ItemLinks.Add.Item := mnu;
    end;
    mnu := TdxBarSubItem(mnus.Objects[i]);

    btn := TdxBarButton.Create(Self);
    btn.Caption := tTablesTableDescription.AsString;
    btn.Tag := tTablesId.AsInteger;
    btn.OnClick := VocabularyClick;
    mnu.ItemLinks.Add.Item := btn;

    tTables.Next;
  end;
end;

procedure TMainForm.VocabularyClick(Sender: TObject);
var
  btn: TdxBarButton;
begin
  btn := Sender as TdxBarButton;
  CreateVocChild(btn.Tag);
end;

procedure TMainForm.CreateVocChild(const ID: Integer);
var
  Child: TMDIChild;
begin
  { create a new MDI child window }
  Child := TMDIChild.Create(Application);
  Child.ID := ID;
  Child.Init;
end;

procedure TMainForm.dxmAboutClick(Sender: TObject);
begin
  AboutBox.ShowModal;
end;

procedure TMainForm.dxmExitClick(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.dxmNoSkinClick(Sender: TObject);
begin
  dxSkinController1.SkinName := '';
end;

procedure TMainForm.dxmSkinsClick(Sender: TObject);
var
  i: Integer;
begin
  i := dxmSkins.ItemIndex;
  if i >= 0 then
    dxSkinController1.SkinName := dxmSkins.Items[i];
end;

end.
